package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.LeaveRequest;
import com.example.pojo.dto.LeaveRequestDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LeaveRequestMapper extends BaseMapper<LeaveRequest> {
    @Select({
            "SELECT lr.*, si.name AS studentName, si.stu_avatar AS stuAvatar, c.class_name AS className",
            "FROM leave_request lr",
            "JOIN stu_info si ON lr.student_id = si.id",
            "JOIN classes c ON lr.class_id = c.class_id",
//            "JOIN approval a ON lr.leave_id = a.leave_id",
            "WHERE lr.class_id = #{classId} AND lr.leave_status = 1"
    })
    List<LeaveRequestDTO> findLeaveRequestsByClassId(@Param("classId") Long classId);

    @Select({
            "SELECT lr.*, si.name AS studentName, si.stu_avatar AS stuAvatar, c.class_name AS className, a.comments",
            "FROM leave_request lr",
            "JOIN stu_info si ON lr.student_id = si.id",
            "JOIN classes c ON lr.class_id = c.class_id",
            "JOIN approval a ON lr.leave_id = a.leave_id",
            "WHERE lr.class_id = #{classId} AND lr.leave_status != 1"
    })
    List<LeaveRequestDTO> getProcessedLeave(@Param("classId") Long classId);
}
